package com.huowei.htzy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.huowei.htzy.R;
import com.huowei.htzy.util.GlideUtil;
import com.huowei.htzy.util.ViewHolderUtil;

import java.util.List;

/**
 * Created by huowei on 2016/10/12.
 */

public class ImageAdapter extends BaseAdapter{
    private List<String> list;
    private Context context;

    public ImageAdapter(List<String> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.image_adapter,null);
        }

        ImageView imageViewSmall = ViewHolderUtil.get(convertView, R.id.home_adapter_image_small);
        ImageView imageView = ViewHolderUtil.get(convertView, R.id.home_adapter_image);
        if (list.size()>2){
            imageViewSmall.setVisibility(View.VISIBLE);
            imageView.setVisibility(View.GONE);
        }else {
            imageViewSmall.setVisibility(View.GONE);
            imageView.setVisibility(View.VISIBLE);
        }
        GlideUtil.setRequest(context,list.get(position),imageView);
        GlideUtil.setRequest(context,list.get(position),imageViewSmall);
        return convertView;
    }
}
